import java.util.concurrent.LinkedBlockingQueue;

//Tabs = 4
//************************************************************
//	COPYRIGHT 2011 Bread Zeppelin - ALL RIGHTS RESERVED
//
//This file is the product of Bread Zeppelin and cannot be 
//reproduced, copied, or used in any shape or form without 
//the express written consent of Bread Zeppelin.
//************************************************************
//
//	$ID: Concurrent_Assg6
//
//	$Date: Feb 13, 2012
//
//	Reason:
//
//*************************************************************

/** $Author: Ben Hare, Zach Huenink, Philipp Wittmaack, Peter Maresca */
/** $Revision: 1 */

//Default Package

/**
 * Holds CustomerParties until they are ready to be seated by a Hoestess.
 */
public class WaitingList {

	final private int smallParty = 1;
	final private int mediumParty = 4;
	final private int largeParty = 6;

	// Three linked queues to hold the different sized tables.
	private LinkedBlockingQueue<CustomerParty> smallPartyArray;
	private LinkedBlockingQueue<CustomerParty> mediumPartyArray;
	private LinkedBlockingQueue<CustomerParty> largePartyArray;

	/**
	 * WaitingList constructor. Instantiates: small, medium and large, Party Arrays.
	 */
	WaitingList() {

		this.smallPartyArray = new LinkedBlockingQueue<CustomerParty>();
		this.mediumPartyArray = new LinkedBlockingQueue<CustomerParty>();
		this.largePartyArray = new LinkedBlockingQueue<CustomerParty>();

	}

	/**
	 * Adds a customer to the WaitingList.
	 * 
	 * @param cp The customer to be added to the WaitingList.
	 */
	public void addCustomer(CustomerParty cp) {

		if (cp.getPartySize() <= smallParty) {

			smallPartyArray.add(cp);

		} else if (cp.getPartySize() <= mediumParty) {

			mediumPartyArray.add(cp);

		} else {

			largePartyArray.add(cp);
		}
	}

	/**
	 * Returns a CustomerParty matching the requestedSize.
	 * 
	 * @param requestedSize The desired size of party.
	 * @return A customer matching the requestedSize.
	 */
	public CustomerParty getCustomer(int requestedSize) {

		if (requestedSize <= smallParty) {

			return smallPartyArray.poll();

		} else if (requestedSize <= mediumParty) {

			return mediumPartyArray.poll();

		} else if (requestedSize <= largeParty) {

			return largePartyArray.poll();
		} 

		return null;
	}

	public boolean checkWaiting(int requestedSize) {

		if (requestedSize <= smallParty) {

			return !(smallPartyArray.peek() == null );

		} else if (requestedSize <= mediumParty) {

			return !(mediumPartyArray.peek() == null );

		} else if (requestedSize <= largeParty) {

			return !(largePartyArray.peek() == null );
		} 

		return false;
	}

	public int size() {
		
		return smallPartyArray.size()
				+ mediumPartyArray.size()
				+ largePartyArray.size();
		
	}

}
